package com.jelly.exception;

import java.util.HashMap;
import java.util.Map;


import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.jelly.dto.Result;
import com.jelly.exception.BizException;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

	@ExceptionHandler(value = BizException.class)
	@ResponseBody
	public Result bizExceptionHandler(BizException e) {
		return Result.error(e.getStatus().value(), e.getMessage());
	}

	@ExceptionHandler(value = Exception.class)
	@ResponseBody
	public Result exceptionHandler(Exception e) {
		Map<String, Object> map = new HashMap<>();
		map.put("msg", e.getMessage());
		map.put("code", HttpStatus.INTERNAL_SERVER_ERROR.value());
		return Result.error(e.getMessage());
	}
}